<template>
  <div class="EMPIAdministration_SQX">
    <div class="pubBig Privilege">
      <div class="h0">
        <p class="lt"></p>
      </div>
      <div class="dDownMain">
        <div
          class="twoBox"
          :style="
            this.$route.query.Token
              ? 'top:50px;left:10px'
              : 'top: 100px;padding:10px;'
          "
          v-loading="isLoading"
        >
          <div class="top_box">
            <el-input
              size="mini"
              style="width: 20%; display: inline-block"
              placeholder="请输入患者索引号"
              v-model="search_input"
            ></el-input>
            <el-button
              size="mini"
              icon="el-icon-search"
              style="margin-left: 10px"
              @click="getTableData()"
            ></el-button>
            <el-button
              size="mini"
              style="margin-left: 10px"
              @click="(search_input = ''), getTableData()"
              >重置</el-button
            >
            <el-button size="mini" style="margin-left: 10px" @click="clear"
              >开始试清洗</el-button
            >
          </div>
          <div class="bottom_box" style="margin-top: 10px">
            <template>
              <el-table
                :data="tableData"
                border
                style="width: 100%"
                height="600px"
                v-loading="table_loading"
              >
                <el-table-column
                  type="index"
                  label="序号"
                  align="center"
                  width="50px"
                  :index="
                    (index) => {
                      return pages.limit * (pages.page - 1) + index + 1;
                    }
                  "
                >
                </el-table-column>
                <el-table-column prop="LikeCode" label="相似索引">
                </el-table-column>
                <el-table-column prop="LikeName" label="相似名称">
                </el-table-column>
                <el-table-column prop="MergeCode" label="合并索引">
                </el-table-column>
                <el-table-column prop="MergeName" label="合并名称">
                </el-table-column>
                <el-table-column prop="CreateTime" label="操作时间">
                  <template slot-scope="scope">
                    {{ scope.row.CreateTime | dateFormat }}
                  </template>
                </el-table-column>
                <el-table-column prop="CreateUser" label="操作人">
                </el-table-column>
              </el-table>
              <div class="block" style="text-align: center; margin-top: 5px">
                <el-pagination
                  layout="prev, pager, next"
                  :page-size="pages.limit"
                  :current-page.sync="pages.page"
                  :total="pages.total"
                  @current-change="page_change"
                >
                </el-pagination>
              </div>
            </template>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      search_input: "",
      tableData: [],
      pages: {
        page: 1,
        limit: 10,
        total: 1,
      },
      isLoading: false,
      table_loading: false,
    };
  },
  methods: {
    getTableData() {
      this.table_loading = true;
      this.$post(
        "/Patient/TryList?keyword=" +
          this.search_input +
          "&page=" +
          this.pages.page +
          "&limit=" +
          this.pages.limit
      ).then((res) => {
        if (res.code == 0) {
          this.tableData = res.data.list;
          this.pages.total = res.data.TotalCount;
          this.table_loading = false;
        }
      });
    },
    page_change(val) {
      // 页码切换事件

      this.pages.page = val;
      this.getTableData();
    },
    clear() {
      this.isLoading = true;
      this.$post("/Patient/TryClean")
        .then((res) => {
          if (res.code == 0) {
            this.isLoading = false;
            this.$message({
              message: "操作成功",
              type: "success",
            });
          }
        })
        .catch((err) => {
          this.isLoading = false;
          console.log(err);
          this.$message({
            message: "操作失败",
            type: "error",
          });
        });
    },
  },
  mounted() {
    // document.getElementById("2").focus();
    this.getTableData();
  },
  created() {
    if (this.$route.query.Token) {
      localStorage.setItem("Token", this.$route.query.Token);
    }
  },
  filters: {
    dateFormat(val) {
      if (val == null || val == "") {
        return "";
      } else {
        let d = new Date(val); // val 为表格内取到的后台时间
        let month =
          d.getMonth() + 1 < 10 ? "0" + (d.getMonth() + 1) : d.getMonth() + 1;
        let day = d.getDate() < 10 ? "0" + d.getDate() : d.getDate();
        let hours = d.getHours() < 10 ? "0" + d.getHours() : d.getHours();
        let min = d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes();
        let sec = d.getSeconds() < 10 ? "0" + d.getSeconds() : d.getSeconds();
        let times =
          d.getFullYear() +
          "-" +
          month +
          "-" +
          day +
          " " +
          hours +
          ":" +
          min +
          ":" +
          sec;
        return times;
      }
    },
  },
};
</script>
<style lang="scss">
.EMPIAdministration_SQX {
  .top-input {
    display: inline-block;
    width: 350px;
  }

  .box-top {
    margin-top: 15px;
    margin-left: 5px;
  }
}
</style>
